// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/common/file/temp_file_path.h>

#include <pollux/connectors/hive/storage_adapters/abfs/AzureDataLakeFileClient.h>

using namespace Azure::Storage::Files::DataLake::Models;

namespace kumo::pollux::filesystems {

// A mock AzureDataLakeFileClient backend with local file store.
class MockDataLakeFileClient : public AzureDataLakeFileClient {
 public:
  MockDataLakeFileClient() {
    auto tempFile = pollux::exec::test::TempFilePath::create();
    filePath_ = tempFile->getPath();
  }

  MockDataLakeFileClient(std::string_view filePath) : filePath_(filePath) {}

  std::string_view path() const {
    return filePath_;
  }

  void create() override;

  PathProperties getProperties() override;

  void append(const uint8_t* buffer, size_t size, uint64_t offset) override;

  void flush(uint64_t position) override;

  void close() override;

  std::string getUrl() const override {
    return "testUrl";
  }

  // for testing purpose to verify the written content if correct.
  std::string readContent() {
    std::ifstream inputFile(filePath_);
    std::string content;
    inputFile.seekg(0, std::ios::end);
    std::streamsize fileSize = inputFile.tellg();
    inputFile.seekg(0, std::ios::beg);
    content.resize(fileSize);
    inputFile.read(&content[0], fileSize);
    inputFile.close();
    return content;
  }

 private:
  std::string filePath_;
  std::ofstream fileStream_;
};
} // namespace kumo::pollux::filesystems
